<template>
  <el-dialog
    class="dialog-face"
    v-model="visible"
    width="80%"
    :show-close="false"
    style="--el-dialog-padding-primary: unset"
    @opened="onOpen"
    @close="onClose"
  >
    <template #header>
      <div class="header">考勤打卡</div>
    </template>
    <div class="section">
      <div class="section-left">
        <template v-if="detail?.face_image">
          <img
            class="avatar"
            :src="detail.face_image"
          />
        </template>
        <template v-else>
          <div
            class="avatar avatar-blue"
            style="display: flex; align-items: center; justify-content: center"
            :class="userType == 1 ? 'avatar-blue' : 'avatar-pink'"
          >
            <img :src="require(`@/assets/avatar0${userType}.png`)" />
          </div>
        </template>
        <div class="text">姓名：{{ detail?.name || "-" }}</div>
        <div class="text">{{ detail?.account_no }}</div>
        <div class="text status">
          {{ detail?.name ? "验证通过" : "识别中..." }}
        </div>
      </div>
      <div class="section-right">
        <div style="margin-left: 44px">
          <div class="face-wrap">
            <FaceWrap
              ref="faceWrapRef"
              :user-type="userType"
              @punch="onPunch"
            />
          </div>
          <p>刷卡或人脸识别考勤打卡</p>
        </div>
        <div style="margin-left: 44px">
          <div class="qr">
            <img
              style="width: 100%; height: 100%"
              :src="qrSrc"
            />
          </div>
          <p>扫码打卡</p>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script setup>
import { computed, defineProps, defineEmits, ref, inject } from "vue";
import { ElMessage, ElNotification, ElDialog } from "element-plus";
import { clazz } from "@/api/apiData";
import FaceWrap from "@/components/FaceWrap/index.vue";
const { deviceDetail } = inject("global-stroe");
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
  userType: {
    type: [String, Number], // 身份类型:1=学生,2=教师
  },
});
const emits = defineEmits(["update:modelValue", "close"]);
const visible = computed({
  get() {
    return props.modelValue;
  },
  set(newVal) {
    emits("update:modelValue", newVal);
  },
});
const detail = ref({});
const faceWrapRef = ref();
const onOpen = () => {
  faceWrapRef.value.init();
  getQrSrc();
};
const onClose = () => {
  detail.value = {};
  emits("close");
  faceWrapRef.value.destroy();
};

const qrSrc = ref();
const getQrSrc = () => {
  const room_id = deviceDetail.value?.room_id;
  clazz.room
    .getClassRoomInfo({
      room_id,
    })
    .then(({ data }) => {
      qrSrc.value = data?.course_info?.lesson_qrcode;
    });
};
const onPunch = (data) => {
  detail.value = data;
};
</script>

<style
  lang="less"
  scoped
>
.dialog-face {
  .header {
    width: 100%;
    height: 68px;
    line-height: 68px;

    background: linear-gradient(90deg, #56abf9 0%, #5686fc 100%);

    font-weight: 500;
    font-size: 32px;
    color: #ffffff;

    text-align: center;
  }
  .section {
    display: flex;
    align-items: center;
    padding: 34px 121px 58px 75px;
    &-left {
      padding-right: 97px;
      border-right: 1px solid #dcdcdc;
      .avatar {
        width: 331px;
        height: 391px;
        background: #cccccc;
        border-radius: 4px;
        &-blue {
          background: #d5e3ff;
        }

        &-pink {
          background: #ffd5d5;
        }
      }
      .text {
        font-size: 24px;
        color: #333333;
        margin-bottom: 16px;
        &:first-of-type {
          margin-top: 20px;
        }
      }
      .status {
        color: #00d146;
      }
    }
    &-right {
      /* 770px x 454px */
      display: flex;
      .face-wrap {
        /* 560px x 330px */
        width: 560px;
        height: 330px;
        padding: 4px;
        background: url("@/assets/face-bg.png") no-repeat center/100% 100%;
        box-sizing: border-box;
      }
      .qr {
        /* 330px x 330px */
        display: block;
        width: 330px;
        height: 330px;
        padding: 4px;
        background: url("@/assets/qr-bg.png") no-repeat center/100% 100%;
        box-sizing: border-box;
      }
      p {
        margin-top: 26px;
        text-align: center;
        font-size: 32px;
        color: #5688fc;
      }
    }
  }
}
</style>
<style lang="less">
.custom-message {
  padding: 20px;
  font-size: 40px;
  .el-message__content {
    font-size: inherit !important;
  }
}
</style>
